package com.tianji.aigc.controller;

import com.tianji.aigc.domain.dto.ChatDTO;
import com.tianji.aigc.domain.vo.ChatEventVO;
import com.tianji.aigc.service.IChatService;
import com.tianji.common.annotations.NoWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/7/21 15:14
 */
@Slf4j
@RestController
@RequestMapping("/chat")
@RequiredArgsConstructor
public class ChatController {
    private final IChatService chatService;

    /**
     * 1、流式聊天 （Day1 - 随堂3）
     * @param chatDTO
     * @return
     */
    @NoWrapper
    @PostMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatEventVO> chat(@RequestBody ChatDTO chatDTO){
        return chatService.chat(chatDTO.getQuestion(),chatDTO.getSessionId());
    }
    /**
     * 2、流式聊天 （Day1 - 随堂4）
     * @param chatDTO
     * @return
     */

    @PostMapping("stop")
    public void stop(@RequestParam("sessionId") String sessionId){
        chatService.stop(sessionId);
    }
}
